#!/usr/bin/env python3
# -*- coding:utf-8 -*-

import re
import setuptools
import glob
import os
import pybind11
import sys


with open("spirems/__init__.py", "r") as f:
    version = re.search(
        r'^__version__\s*=\s*[\'"]([^\'"]*)[\'"]',
        f.read(), re.MULTILINE
    ).group(1)


with open("README.md", "r", encoding="utf-8") as f:
    long_description = f.read()


def get_package_data():
    data = []
    data.append('msgs/_sys_msgs/*.json')
    data.append('msgs/_visual_msgs/*.json')
    data.append('msgs/_config_msgs/*.json')
    data.append('json_msgs/geometry_msgs/*.json')
    data.append('json_msgs/memory_msgs/*.json')
    data.append('json_msgs/sensor_msgs/*.json')
    data.append('json_msgs/spirecv_msgs/*.json')
    data.append('json_msgs/std_msgs/*.json')
    data.append('json_msgs/nav_msgs/*.json')
    data.append('json_msgs/vehicle_msgs/*.json')
    data.append('json_schemas/geometry_msgs/*.json')
    data.append('json_schemas/sensor_msgs/*.json')
    data.append('json_schemas/std_msgs/*.json')
    data.append('foxglove/schema/*.json')
    data.append('logs/*.md')
    data.append('res/*.ttf')
    data.append('res/*.jpg')
    data.append('res/*.csv')
    data.append('res/*.json')
    return {'spirems': data}


current_os = sys.platform
if current_os.startswith('linux'):
    ext_modules = [
        setuptools.Extension(
            "spirems.exts.csms_shm",
            sources=["spirems/exts/csms_shm.cpp"],
            include_dirs=[pybind11.get_include()],
            extra_compile_args=['-std=c++11'],
            extra_link_args=['-lrt'],
            language="c++",
        ),
    ]
elif current_os.startswith('darwin'):
    ext_modules = [
        setuptools.Extension(
            "spirems.exts.csms_shm",
            sources=["spirems/exts/csms_shm.cpp"],
            include_dirs=[pybind11.get_include()],
            extra_compile_args=['-std=c++11'],
            language="c++",
        ),
    ]
else:
    ext_modules = None


setuptools.setup(
    name="spirems",
    version=version,
    author="jario",
    author_email="renjin@bit.edu.cn",
    python_requires=">=3.8",
    long_description=long_description,
    long_description_content_type='text/markdown',
    classifiers=["Programming Language :: Python :: 3", "Operating System :: OS Independent"],
    ext_modules=ext_modules,
    package_dir={'spirems': 'spirems'},
    package_data=get_package_data(),
    packages=setuptools.find_packages(),
    entry_points={
        'console_scripts': [
            'smscore=spirems.core:main',
            'sms=spirems.sms:main',
            'smsservice=spirems.smsservice:main',
            'smsparam=spirems.smsparam:main',
            'smsfox=spirems.foxglove.foxglove_server:foxglove_main',
            'smslog=spirems.logsaver:main',
            'smsvis=spirems.nodes.Targets2DVisNode:main',
            'sms2udps=spirems.interface.sms2udps:main',
            'smsbag=spirems.smsbag:main'
        ],
    },
    install_requires=("numpy", "opencv-python", "psutil", "jsonschema")
)
